<template>
	<view>
		<view v-if="isLogin">
			<!-- 主页第一部分 -->
			<view class="head-container">
				<image :src="avatar" mode="" class="img-avatar"></image>
				<view class="teacher-container">
					<text class="teacher-zhong">{{nick+"["+userTypes[type]+"]"}}</text>
				</view>
				<text class="iconfont icon-zhuxiao" @click="zhuxiao"></text>
			</view>

			<!-- 主页第二部分 -->
			<view class="body-container">
				<view class="gr-zx" >
					<text class="iconfont icon-iconfontgerenzhongxin2 "> </text>
					<text class="GR-ZX">个人中心</text>
				</view>
				<view v-if="type == 1" class="kc-gl" >
					<text class="iconfont icon-xianshangkecheng"  @click="goCourseGL"> </text>
					<text class="KC-GL">课程管理</text>
				</view>
				<view v-if="type == 1" class="xs-gl">
					<text class="iconfont icon-zaijixueshengguanli"> </text>
					<text class="XS-GL">学生管理</text>
				</view>
				<view v-if="type == 1" class="tj-kc">
					<text class="iconfont icon-tianjiakecheng" @click="goCourseTJ" > </text>
					<text class="TJ-KC">添加课程</text>
				</view>
				<view v-if="type == 2" class="tj-kc">
					<text class="iconfont icon-xianshangkecheng"> </text>
					<text class="KC-LB">课程列表</text>
				</view>
				<view v-if="type == 0" class="tj-kc" >
					<text class="iconfont icon-zaijixueshengguanli "@click="clickUser" > </text>
					<text class="YH-GL">用户管理</text>
				</view>
				<view v-if="type == 0" class="tj-kc">
					<text class="iconfont icon-zhanghaoquanxianguanli"> </text>
					<text class="QX-MK-GL">权限模块管理</text>
				</view>
			</view>
		</view>
		<login-dialog ref="login" @after="afterLogin"></login-dialog>
	</view>
</template>
<script>
	let app = getApp()
	export default {
		data() {
			return {
				avatar: "",
				type: app.globalData.type,
				name: '',
				nick: '',
				email: '',
				isLogin: false,
				userTypes: ["管理员", "教师", "学生"],
			}
		},
		onLoad() {

		},
		//让当前页面下拉刷新
		onPullDownRefresh() {
			if (this.isLogin == false) {
				this.$refs.login.show()
			}
			uni.stopPullDownRefresh()
		},
		mounted() {
			if (!this.isLogin) {
				this.$refs.login.show()
			}
		},
		methods: {
			afterLogin(logout) {
				if (logout) {
					this.$refs.login.show()
					return
				}
				if (this.isLogin) {
					return
				}
				this.isLogin = app.globalData.token.length > 0
				this.avatar = this.$params.host + app.globalData.avatar
				this.name = app.globalData.userName
				this.nick = app.globalData.nickName
				this.email = app.globalData.email
				this.type = app.globalData.type
			},
			clickToLogin() {
				this.isLogin = false
				app.globalData.uid = ''
				app.globalData.type = -1
				app.globalData.email = ''
				app.globalData.nickName = ''
				app.globalData.userName = ''
				app.globalData.phone = ''
				app.globalData.apply = ''
				app.globalData.token = ''
				this.$noti.post(this.$params.noti_login_status, true)
				this.$refs.login.show()
			},
			zhuxiao() {
				this.isLogin = false

				this.$refs.login.show()
			},
			clickUser(){
				uni.navigateTo({
					url:'./../User/User',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
   goCourseGL(){
				uni.navigateTo({
					url: '../teacher/courseGL/courseGL',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
	goCourseTJ(){
					uni.navigateTo({
						url: '../teacher/courseTJ/courseTJ',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				},
			}
		}
</script>

<style>
	@import url("index.css");

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>